#ifndef _UTILS_H_
#define _UTILS_H_
#include "DataStructure.h"
#include <math.h>
#define EPSILON 1e-6
enum QUALITY 
{
	QUALITY_LOW = 0,
	QUALITY_HIGH,
};
enum INTERPOLATION_FUNC
{
	IF_LINEAR =0,
	IF_QUADRATIC, 
	IF_STEP,
};
enum FIXED_POINT_FORMAT
{
	// FP_SIGN-BITS_INTEGER-BITS_FRAC-BITS
	FP_0_0_16 = 16,
	FP_0_1_15 = (1<<8)+15,
	FP_0_2_14 = (2<<8)+14,
	FP_0_3_13 = (3<<8)+13,
	FP_0_4_12 = (4<<8)+12,

	FP_1_0_15 = (1<<16)+15,
	FP_1_1_14 = (1<<16)+(1<<8)+14,
	FP_1_2_13 = (1<<16)+(2<<8)+13,
	FP_1_3_12 = (1<<16)+(3<<8)+12,

	FP_1_15_16 = (1<<16)+(15<<8)+16,
};
// Get fixed point format string
string getFixedPointStr(FIXED_POINT_FORMAT type);
// Get fixed point format size ( in bytes)
int getFixedPointSize(FIXED_POINT_FORMAT type);
// 
uint floatToFixed(float f,FIXED_POINT_FORMAT type);
// Find the fp format that best fit with data in a arrayVec3 
FIXED_POINT_FORMAT findFixedPointFormat(arrayVec3& a);
// Find the fp format that best fit with data in a arrayVec2 
FIXED_POINT_FORMAT findFixedPointFormat(arrayVec2& a);

// Split a string into many substring
void split(string in,vector<string>& out, char separator);
// String to float
float stof(string in);
// String to integer
int stoi(string in);
bool isEqual(float n1,float n2,float e);

// Check the a element is in an array or not
// Return : offset of this element in array ( -1 if not In)
template <class T>
int isIn(T val, vector<T> vec)
{
	for(int i=0;i< vec.size();i++)
	{
		if( val==vec[i])
			return i;
	}
	return -1;
}
#endif